package com.google.code.memoriesalbum;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;

import com.google.gdata.data.media.BaseMediaSource;
import com.google.gdata.data.media.MediaSource;

/**
 * バイト配列でデータを保持する{@link MediaSource}の実装.
 * @author shin1ogawa
 */
public class MediaByteArraySource extends BaseMediaSource {

	byte[] byteArray;


	/**
	 * the constructor.
	 * @param byteArray
	 * @param mediaType {@link BaseMediaSource}
	 * @category constructor
	 */
	public MediaByteArraySource(byte[] byteArray, String mediaType) {
		super(mediaType);
		if (byteArray == null) {
			this.byteArray = new byte[0];
		} else {
			this.byteArray = byteArray;
		}
	}

	@Override
	public InputStream getInputStream() {
		return new ByteArrayInputStream(byteArray);
	}

	@Override
	public OutputStream getOutputStream() {
		throw new UnsupportedOperationException("Cannot write to "
				+ MediaByteArraySource.class.getSimpleName());
	}
}
